<template>
  <div>
    <h1>我的新闻</h1>
      <el-col
        :span="20"
        v-for="(a,index) in news1"
        :key="a.id"
        :offset="index =0"
      >
        <el-card :body-style="{ padding: '0px' }">
          <div class="left">
            <el-image
              style="width: 150px; height: 150px"
              :src="'http://120.77.71.211:9090/mynewsweb/'+a.path"
              class="image"
              fist="fill">
            </el-image>
          </div>

          <div style="padding: 14px">
            <div class="con">
              <a :href="'#/showMyNews?id='+a.id"><h1>{{a.title}}</h1></a><br>
              <a>{{a.summary}}</a>
              <div class="bottom clearfix">
                <span class="left">{{a.writer}}</span>
                <span class="right">{{a.time}}&nbsp;&nbsp;<el-button type="danger" plain v-on:click="delet(a)">删除</el-button></span>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
  </div>
</template>

<script>
export default {
    name:"MyNews",
    data() {
        return {
        activeIndex: 'entertainment',
        user: {
                    userId:"",
                },//用来存放用户登录信息
        news1:[]
        }
    },
   methods:{
        delet(news){
            this.$axios.post("http://120.77.71.211:9090/mynewsweb/api/deleteNew",news).then((res) => {
                if (res.data.state) {
                    alert(res.data.msg);
                     this.showMyNews();
                    this.$router.push("#/mainTable");
                } else {
                    alert(res.data.msg);
                }
            });
        },
        showMyNews(){
          var userString = localStorage.getItem("user");
        this.user = JSON.parse(userString);
        var userId=this.user.userId;
        var _this=this;
        this.$axios.get("http://120.77.71.211:9090/mynewsweb/api/findNewByuserId?userId="+userId).then((res) => {
            _this.news1=res.data;
        });
        }
    },
    

    // 生命周期
    created(){
        this.showMyNews();
    }
}
</script>

<style>
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    float: right;
  }

  .image {
    width: 100%;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
      display: table;
      content: "";
  }
  
  .clearfix:after {
      clear: both
  }

  .left{
    float: left;
    width:150px; 
    height:100%
  }

  .right{
    float: right;
  }

  .con{
    padding-left: 160px;
    position:relative;
  }

  a:link{
    color: rgb(64, 72, 145);
  }
  a:visited{
    color: rgb(67, 72, 145);
  }
  a{ text-decoration:none} 
      
</style>